﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Checkout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void saleItems()
    {
        List<CartItem> list = (List<CartItem>)Session["list"];
        //orderdetail ordDetail = new orderdetail();
        //ordDetail.
        order ord = new order();
        ord.member_id = Session["login"].ToString();
        ord.orderDate = DateTime.Now;
        ord.ship_address = txtAddress.Text.Trim();
        ord.ship_email = txtEmail.Text.Trim();
        ord.ship_first_name = txtFirstName.Text.Trim();
        ord.ship_last_name = txtLastName.Text.Trim();
        ord.ship_phone = txtPhone.Text.Trim();
        foreach (CartItem c in list)
        {
            orderdetail odt = new orderdetail();
            odt.item_id = c.ItemID;
            odt.Quantity = c.Quantity;
            odt.UnitPrice = c.Price;

            ord.orderdetails.Add(odt);
        }

        BookStoreDataContext bs = new BookStoreDataContext();
        bs.orders.InsertOnSubmit(ord);
        bs.SubmitChanges();

    }
    protected void btnCommit_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            saleItems();
            Response.Redirect("CommitSuccess.aspx");
        }
    }
}